package com.atguigu.tingshu.order.api;

import com.atguigu.tingshu.common.anno.AuthLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.order.OrderInfo;
import com.atguigu.tingshu.order.service.OrderInfoService;
import com.atguigu.tingshu.vo.order.OrderInfoVo;
import com.atguigu.tingshu.vo.order.TradeVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Tag(name = "订单管理")
@RestController
@RequestMapping("api/order/orderInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class OrderInfoApiController {

	@Autowired
	private OrderInfoService orderInfoService;

// 	/api/order/orderInfo/trade
	@AuthLogin
	@PostMapping("/trade")
	public Result<OrderInfoVo> trade(@RequestBody @Validated TradeVo tradeVo){
		return Result.ok(orderInfoService.trade(tradeVo));
	}

// 	/api/order/orderInfo/submitOrder
	@AuthLogin
	@PostMapping("submitOrder")
	public Result<Map<String,Object>> submitOrder(@RequestBody @Validated OrderInfoVo orderInfoVo){
		String orderNo = orderInfoService.submitOrder(orderInfoVo);
		Map<String, Object> map = new HashMap<String , Object>();
		map.put("orderNo", orderNo);
		return Result.ok(map);
	}

// 	/api/order/orderInfo/getOrderInfo/9d67acf2943f4b3f93e411fcc92da775
	@AuthLogin
	@GetMapping("/getOrderInfo/{orderNo}")
	public Result<OrderInfo> getOrderInfo(@PathVariable String orderNo){
		return Result.ok(orderInfoService.getOrderInfoByOrderNo(orderNo));
	}
// 	/api/order/orderInfo/findUserPage/1/10
	@AuthLogin
	@GetMapping("findUserPage/{pageNo}/{pageSize}")
	public Result<IPage<OrderInfo>> findUserPage(@PathVariable Integer pageNo,@PathVariable Integer pageSize){
		return Result.ok(orderInfoService.findUserPage(pageNo,pageSize));
	}
}

